/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistemperpustakaan.model;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.management.Query;
import javax.swing.JOptionPane;
import sistemperpustakaan.entity.Bahasa;
import sistemperpustakaan.entity.Buku;
import sistemperpustakaan.entity.Jenis;
import sistemperpustakaan.entity.Kategori;
import sistemperpustakaan.entity.Penerbit;
import sistemperpustakaan.entity.ViewBuku;
import sistemperpustakaan.utility.DbUtility;

/**
 *
 * @author EKo
 */
public class BukuModel {

    Connection connection;
    List<ViewBuku> listBuku;
    Vector vectorJenis;
    Vector vectorKategori;
    Vector vectorPenerbit;
    Vector vectorBahasa;
    Buku buku;
    Penerbit penerbit;
    ViewBuku lb;
    List<Jenis> listJenis;
    List<Penerbit> listPenerbit;

    public BukuModel() {
        connection = new DbUtility().getConnection();
    }

    public Connection getConnection() {
        return connection;
    }

    public boolean insertBuku(int id, String no_panggil, String isbn, String judul, String pengarang, int penerbit, int tahun, int bahasa, int jenis, int kategori, String subyek, int jumlah_halaman) {
        String query = "INSERT INTO BUKU "
                + "(id, no_panggil, isbn, judul, pengarang, penerbit_id, tahun, bahasa_id, jenis_id, kategori_id, subyek,jumlah_halaman) "
                + "VALUES(fGenerateIdBuku(),'" + no_panggil + "','" + isbn + "','" + judul + "','" + pengarang + "'," + penerbit + " ," + tahun + " ," + bahasa + " ," + jenis + " ," + kategori + " ,'" + subyek + "'," + jumlah_halaman + " )";
        PreparedStatement statement = null;
        
        try {
            statement = connection.prepareStatement(query);
            //for(int i=1;i<=10;i++) statement.setObject(i, b.getObject(i));
            connection.setAutoCommit(false);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when insert data\n Error: " + ex.getMessage());
            try {
                connection.rollback();
            } catch (SQLException exr) {
            }
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean updateBuku(String id, String no_panggil, String isbn, String judul, String pengarang, int penerbit, int tahun, int bahasa, int jenis, int kategori, String subyek, int jumlah_halaman, int id_lama) {
        String query = "UPDATE BUKU SET "
                + "id=" + id + ", no_panggil='" + no_panggil + "',isbn='" + isbn + "',judul='" + judul + "',pengarang='" + pengarang + "',penerbit_id=" + penerbit + ",tahun=" + tahun + ",bahasa_id=" + bahasa + ",jenis_id=" + jenis + ",kategori_id=" + kategori + ",subyek='" + subyek + "',jumlah_halaman=" + jumlah_halaman + ""
                + " WHERE id=" + id_lama;
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement(query);
            //for(int i=1;i<=10;i++) statement.setObject(i, b.getObject(i));
            //statement.setInt(11, b.getId());
            connection.setAutoCommit(false);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }

//            System.out.println(query);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when update data\n Error: " + ex.getMessage());
            try {
                connection.rollback();
            } catch (SQLException exr) {
            }
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean deleteBuku(int id) {
        String query = "DELETE FROM BUKU WHERE id= '" + id + "'";
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            statement = connection.prepareStatement(query);
            //statement.setString(1, id);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when delete data\n Error: " + ex.getMessage());
            try {
                connection.rollback();
            } catch (SQLException exr) {
            }
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public Buku getBuku(int id) {
        String query = "SELECT * FROM buku WHERE id= '" + id + "'";
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement(query);
            //statement.setString(1, id);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                buku = new Buku(rs.getInt(1), rs.getString(2), rs.getString(3),
                        rs.getString(4), rs.getString(5), rs.getInt(6), rs.getInt(7),
                        rs.getInt(8), rs.getInt(9), rs.getInt(10), rs.getString(11), rs.getInt(12));

            }
            //System.out.println(query);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data buku" + ex.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return buku;
    }

    public Buku generateIdBuku() {
        PreparedStatement statement = null;
        Buku buku = null;
        try {
            statement = connection.prepareStatement("SELECT fGenerateIdBuku() AS Kode");
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                buku = new Buku(rs.getInt(1), null, null, null, null, 0, 0, 0, 0, 0, null, 0);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return buku;
    }

    public Penerbit getPenerbit(int id) {
        String query = "SELECT * FROM penerbit  WHERE id=" + id;
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement(query);
            //statement.setInt(1, id);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                penerbit = new Penerbit(rs.getInt(1), rs.getString(2), rs.getString(3),
                        rs.getString(4), rs.getString(5), rs.getString(6));
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data penerbit" + ex.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return penerbit;
    }

    public ViewBuku getListBuku(int id) {
        String query = "SELECT * FROM vBuku WHERE id=" + id;
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement(query);
            statement.setInt(1, id);
            ResultSet rs = statement.executeQuery(query);
            if (rs.next()) {
                lb = new ViewBuku(rs.getString(1), rs.getString(2), rs.getString(3),
                        rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7),
                        rs.getInt(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getInt(13), rs.getInt(14), rs.getInt(15), rs.getInt(16),rs.getInt(17));

            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + ex.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return lb;
    }

    public List<ViewBuku> getListBuku(String noPanggil, String judul, String pengarang, String penerbit, String bahasa, String jenis, String kategori, int opt) {
        listBuku = new ArrayList<ViewBuku>();
        String query = "CALL pCariBuku ('" + noPanggil + "','" + judul + "','" + pengarang + "','" + penerbit + "','" + bahasa + "','" + jenis + "','" + kategori + "'," + opt+")";

        CallableStatement statement = null;
        try {
            statement = connection.prepareCall(query);
            ResultSet rs = statement.executeQuery();
            while (rs.next()) {
                lb = new ViewBuku(rs.getString(1), rs.getString(2), rs.getString(3),
                        rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7),
                        rs.getInt(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getInt(13), rs.getInt(14), rs.getInt(15), rs.getInt(16),rs.getInt(17));

                listBuku.add(lb);
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + ex.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return listBuku;
    }

    public Vector getVectorJenis() {
        vectorJenis = new Vector();
        String query = "SELECT nama_jenis from jenis_buku ORDER BY id";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(query);
            vectorJenis.add("");
            while (rs.next()) {
                vectorJenis.add(rs.getString(1));
            }
        } catch (Exception e) {
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return vectorJenis;
    }

    public Vector getVectorBahasa() {
        vectorBahasa = new Vector();
        String query = "SELECT bahasa from Bahasa ORDER BY id";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(query);
            vectorBahasa.add("");
            while (rs.next()) {
                vectorBahasa.add(rs.getString(1));
            }
        } catch (Exception e) {
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return vectorBahasa;
    }

    public Vector getVectorKategori() {
        vectorKategori = new Vector();
        String query = "SELECT nama_kategori from kategori_buku ORDER BY id";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(query);
            vectorKategori.add("");
            while (rs.next()) {
                vectorKategori.add(rs.getString(1));
            }
        } catch (Exception e) {
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return vectorKategori;
    }

    public List<Kategori> getListKategori(int id, String nama) {
        List<Kategori> listKategories = new ArrayList<Kategori>();
        String query = "CALL pCariKategori (" + id + ", '" + nama + "')";
        CallableStatement statement = null;
        try {
            statement = connection.prepareCall(query);
            ResultSet rs = statement.executeQuery();
            while (rs.next()) {
                listKategories.add(new Kategori(rs.getInt(1), rs.getString(2)));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error whene retrieve data \nError: " + e.getLocalizedMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return listKategories;
    }

    public Vector getVectorPenerbit() {
        vectorPenerbit = new Vector();
        String query = "SELECT nama_penerbit from penerbit ORDER BY id";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(query);
            vectorPenerbit.add("");
            while (rs.next()) {
                vectorPenerbit.add(rs.getString(1));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return vectorPenerbit;
    }

    public Kategori getKategori(int idKategori) {
        PreparedStatement statement = null;
        Kategori kategori = null;
        try {
            statement = connection.prepareStatement("SELECT * FROM kategori_buku WHERE id=" + idKategori);
//            statement.setInt(1, idKategori);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                kategori = new Kategori(rs.getInt(1), rs.getString(2));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return kategori;
    }

    public boolean insertKategori(int id, String kategori) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            statement = connection.prepareStatement("INSERT INTO kategori_Buku VALUES(fGenerateIdKategori(),'" + kategori + "')");
            //statement.setString(1, kategori);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when insert data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean updateKategori(int id, String kategori, int id_lama) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            String query = "UPDATE kategori_buku SET nama_kategori='" + kategori + "',id=" + id + " WHERE id=" + id_lama + "";
            statement = connection.prepareStatement(query);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }

        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when update data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean deleteKategori(int id) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            statement = connection.prepareStatement("DELETE FROM kategori_buku  WHERE id=" + id);
//            statement.setInt(1, id);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when delete data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public Kategori generateIdKategori() {
        PreparedStatement statement = null;
        Kategori kategori = null;
        try {
            statement = connection.prepareStatement("SELECT fGenerateIdKategori() AS Kode");
//            statement.setInt(1, idKategori);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                kategori = new Kategori(rs.getInt(1), "");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return kategori;
    }

    public Bahasa getBahasa(int idBahasa) {
        Bahasa bahasa = null;
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement("SELECT * FROM bahasa WHERE id=" + idBahasa);
//            statement.setInt(1, idBahasa);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                bahasa = new Bahasa(rs.getInt(1), rs.getString(2));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return bahasa;
    }

    public List<Jenis> getListJenis(int id, String nama) {
        listJenis = new ArrayList<Jenis>();
        CallableStatement statement = null;
        Jenis jenis;
        try {
            statement = connection.prepareCall("CALL pCariJenis (" + id + ", '" + nama + "')");
            ResultSet rs = statement.executeQuery();
            while (rs.next()) {
                jenis = new Jenis(rs.getInt(1), rs.getString(2));
                listJenis.add(jenis);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return listJenis;
    }

    public Jenis getJenis(int idJenis) {
        Jenis jenis = null;
        PreparedStatement statement = null;
        try {
            statement = connection.prepareStatement("SELECT * FROM jenis_buku WHERE id=" + idJenis);
//            statement.setInt(1, idJenis);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                jenis = new Jenis(rs.getInt(1), rs.getString(2));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return jenis;
    }

    public boolean insertJenis(int id, String newJenis) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            statement = connection.prepareStatement("INSERT INTO jenis_buku VALUES (fGenerateIdJenis(),'" + newJenis + "')");
            //statement.setInt(1, id);
            //statement.setString(2, newJenis);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when insert data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean updateJenis(int id, String newJenis, int id_lama) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            String query = "UPDATE jenis_buku SET nama_jenis='" + newJenis + "', id=" + id + " WHERE id=" + id_lama + " ";
            statement = connection.prepareStatement(query);
            //statement.setString(1, newJenis);
            //statement.setInt(2, id);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }

        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when update data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean deleteJenis(int id) {
        PreparedStatement statement = null;
        try {
            String query = "DELETE FROM jenis_buku WHERE id=" + id;
            connection.setAutoCommit(false);
            statement = connection.prepareStatement(query);

            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
//            System.out.println(query);
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when update data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public Jenis generateIdJenis() {
        PreparedStatement statement = null;
        Jenis jenis = null;
        try {
            statement = connection.prepareStatement("SELECT fGenerateIdJenis() AS Kode");
//            statement.setInt(1, idKategori);
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                jenis = new Jenis(rs.getInt(1), "");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return jenis;
    }

    public List<Penerbit> getListPenerbit(int id, String nama, String alamat, String kota, String email, String telepon) {
        listPenerbit = new ArrayList<Penerbit>();
        CallableStatement statement = null;
        try {
            String query = "CALL pCariPenerbit (" + id + ",'" + nama + "','" + alamat + "','" + kota + "','" + email + "','" + telepon + "')";
            statement = connection.prepareCall(query);

            ResultSet rs = statement.executeQuery();
            while (rs.next()) {
                penerbit = new Penerbit(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6));
                listPenerbit.add(penerbit);
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when delete data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return listPenerbit;
    }

    public boolean insertPenerbit(int id, String nama, String alamat, String kota, String email, String telepon) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            String query = "INSERT INTO penerbit (id,nama_penerbit, alamat, kota, email, telepon) VALUES (fGenerateIdPenerbit(),'" + nama + "','" + alamat + "','" + kota + "','" + email + "','" + telepon + "')";
            statement = connection.prepareStatement(query);
            //statement.setInt(1, penerbit.getId());
            //for (int i = 1; i < 6; i++) { statement.setString(i, penerbit.getObject(i).toString()); }
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when insert data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean updatePenerbit(int id, String nama, String alamat, String kota, String email, String telepon, int id_lama) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            String query = "UPDATE penerbit SET id=" + id + ",nama_penerbit='" + nama + "', alamat='" + alamat + "', kota='" + kota + "', email='" + email + "', telepon='" + telepon + "' WHERE id=" + id_lama;
            statement = connection.prepareStatement(query);
            //for (int i = 1; i < 6; i++) { statement.setString(i, penerbit.getObject(i).toString()); }
            //statement.setInt(6, penerbit.getId());
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
            //System.out.println(query);
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when update data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public boolean deletePenerbit(int idPenerbit) {
        PreparedStatement statement = null;
        try {
            connection.setAutoCommit(false);
            statement = connection.prepareStatement("DELETE FROM penerbit WHERE id=?");
            statement.setInt(1, idPenerbit);
            if (statement.executeUpdate() == 1) {
                connection.commit();
            }
        } catch (Exception e) {
            try {
                connection.rollback();
                statement.close();
            } catch (Exception ex) {
            }
            JOptionPane.showMessageDialog(null, "Error when delete data" + e.getMessage());
            return false;
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return true;
    }

    public Penerbit generateIdPenerbit() {
        PreparedStatement statement = null;
        Penerbit penerbit = null;
        try {
            statement = connection.prepareStatement("SELECT fGenerateIdPenerbit() AS Kode");
            ResultSet rs = statement.executeQuery();
            if (rs.next()) {
                penerbit = new Penerbit(rs.getInt(1), null, null, null, null, null);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error when retrieve data" + e.getMessage());
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
        return penerbit;
    }
}
